library _;

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/Const/IFinal.dart';
import 'package:flutter_app/Model/MessageModel.dart';
import 'package:flutter_app/Model/UserModel.dart';
import 'package:flutter_app/Page/Main/Main/Cart/main.dart';
import 'package:flutter_app/Page/Main/Main/Home/main.dart';
import 'package:flutter_app/Page/Main/Main/Message/main.dart';
import 'package:flutter_app/Page/Main/Main/Mine/main.dart';
import 'package:flutter_app/Page/Main/Main/Video/main.dart';
import 'package:flutter_app/Plugin/AppPlugin.dart';
import 'package:flutter_app/Util/App/AppUtils.dart';
import 'package:flutter_app/Util/MessageUtils.dart';
import 'package:flutter_app/View/MyViews.dart';
import 'package:flutter_yfree/YFree.dart';
import 'package:flutter_yfree/extension/flutter_bottom_tab_bar/bottom_tab_bar.dart';
import 'package:flutter_yim/YIM.dart';
import 'package:vibration/vibration.dart';

part 'controller.dart';

part 'view.dart';

class MainPage extends YPage {
  MainPage({this.goLogin = false});

  bool goLogin;

  final mainPage_home = MainPage_Home(), mainPage_video = MainPage_Video(), mainPage_message = MainPage_Message(), mainPage_cart = MainPage_Cart(), mainPage_mine = MainPage_Mine();
  List<YPage> homePages = [];

  final navBarHeight = 60.0;
  var currentIndex = 0, pageController = PageController(initialPage: 0), pages = <YStatefulWidget>[];
  var badge_message_count = 0, badge_message_isDraging = false;

  @override
  void yOnCreate() async {
    IFinal.Others.mainPage = this;
    if (goLogin) AppUtils.checkIsLogon(yPage, goLogin: true);
    homePages = [
      mainPage_home,
      mainPage_video,
      mainPage_message,
      mainPage_cart,
      mainPage_mine,
    ];
    pages = homePages.map((e) => YStatefulWidget(() => e)).toList();
    controller_checkNetLines();
    controller_doScheme();
    controller_registerBroadCast();
    controller_loginYIM();
    controller_reloadHome();
  }

  @override
  void yOnDestory() {
    pageController.dispose();
  }

  @override
  bool ySafeAreaBottom() => false;

  @override
  Widget yBuild(BuildContext context) {
    return WillPopScope(
      onWillPop: () => AppPlugin.goHome(),
      child: Scaffold(
        body: view_body(),
        bottomNavigationBar: view_bottom(),
      ),
    );
  }
}
